
class Vue {
  constructor(option) {
    this.$data = option.data()

    new Observer(this.$data)

  }
}

class Observer {
  constructor(data) {

    if (Array.isArray(data)) {
      this.arrayWalk(data)
    } else {
      this.walk(data)
    }
  }
  // 处理对象
  walk(target) {
    Object.keys(target).forEach(v => {
      defineReactive(target, v)
    })
  }
  // 处理数组
  arrayWalk() {

  }

}

class Compile {

}


// 核心处理响应式函数
function defineReactive(target, key, value) {
  if (arguments.length == 2) {
    value = target[key];
  }

  Object.defineProperty(target, key, {
    get() {
      console.log('get被调用了');
      return value
    },
    set(newValue) {
      console.log('set被调用了');
      value = newValue
    }
  })

}

const arrayMethodArr = [
  'pop',
  'push',
  'shift',
  'unshift',
  'sort',
  'reverse',
  'splice'
]

const arrayMethods = Object.create(Array.prototype);


arrayMethodArr.forEach(v => {

  // 数组原方法
  let originMethod = Array.prototype[v]


})